home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / sbin / gconf-schemas < prev    next >
Encoding:
Text File  |  2009-03-18  |  2.6 KB  |  89 lines

  1. #! /usr/bin/python
  2. #
  3. # copyright (c) 2006 Josselin Mouette <joss@debian.org>
  4. # Licensed under the GNU Lesser General Public License, version 2.1
  5. # See COPYING for details
  6.  
  7. from optparse import OptionParser
  8. import sys,os,os.path,shutil,tempfile
  9.  
  10. parser = OptionParser(usage="usage: %prog --[un]register file1.schemas [file2.schemas [...]]")
  11.  
  12. parser.add_option("--register", action="store_true", dest="register",
  13.                   help="register schemas to the GConf database",
  14.                   default=None)
  15. parser.add_option("--unregister", action="store_false", dest="register",
  16.                   help="unregister schemas from the GConf database",
  17.                   default=None)
  18. parser.add_option("--register-all", action="store_true", dest="register_all",
  19.                    help="clean up the GConf database and register all schemas again",
  20.                    default=False)
  21.  
  22. (options, args) = parser.parse_args()
  23.  
  24. if options.register==None and not options.register_all:
  25.   parser.error("You need to specify --register or --unregister.")
  26.  
  27. schema_location="/usr/share/gconf/schemas"
  28. defaults_dest="/var/lib/gconf/defaults"
  29.  
  30. schemas = [ ]
  31. if options.register_all:
  32.   for f in os.listdir(schema_location):
  33.     if f.endswith(".schemas"):
  34.       schemas.append(os.path.join(schema_location,f))
  35. else:
  36.   for schema in args:
  37.     if not os.path.isabs(schema):
  38.       schema=os.path.join(schema_location,schema)
  39.     if os.path.isfile(schema):
  40.       schemas.append(schema)
  41.     else:
  42.       sys.stderr.write('Warning: %s could not be found.\n'%schema)
  43.  
  44. if len(schemas)<1:
  45.   parser.error("You need at least a file to (un)register.")
  46.  
  47. if os.geteuid():
  48.   parser.error("You must be root to launch this program.")
  49.  
  50. if options.register_all:
  51.   options.register=True
  52.   for f in os.listdir(defaults_dest):
  53.     os.remove(os.path.join(defaults_dest,f))
  54.   open(os.path.join(defaults_dest,"%gconf-tree.xml"),"w").close()
  55.  
  56. tmp_home=tempfile.mkdtemp(prefix='gconf-')
  57. env={'HOME': tmp_home,
  58.      'GCONF_CONFIG_SOURCE': 'xml:readwrite:'+defaults_dest}
  59. if options.register:
  60.   arg='--makefile-install-rule'
  61. else:
  62.   arg='--makefile-uninstall-rule'
  63.  
  64. fd = os.open("/dev/null",os.O_WRONLY)
  65. save_stdout=os.dup(1)
  66. os.dup2(fd,1)
  67. os.close(fd)
  68. res=os.spawnvpe(os.P_WAIT,'gconftool-2',['gconftool-2',arg]+schemas,env)
  69. os.dup2(save_stdout,1)
  70. os.close(save_stdout)
  71.  
  72. shutil.rmtree(tmp_home)
  73.  
  74. if(res):
  75.   sys.exit(res)
  76.  
  77. if options.register:
  78.   # tell running processes to re-read the GConf database
  79.   import signal
  80.   try:
  81.     pids=os.popen('pidof gconfd-2').readlines()[0].split()
  82.     for pid in pids:
  83.       try:
  84.         os.kill(int(pid),signal.SIGHUP)
  85.       except OSError:
  86.         pass
  87.   except IndexError:
  88.     pass
  89.